package model;

/**
 * The MaterialListPriceCached class is a state with a cached MaterialList and a cached overallPrice
 * 
 * @author hfi411pi
 *
 */
public class MaterialListPriceCached extends Cached{
	private final int overallPrice;
	

	/**
	 * Factory method for creating a MaterialListCached state.
	 * @param master is the ComponentCommon of this state.
	 * @param materials is the cached MaterialList.
	 * @param overallPrice is the cached overall price of the master.
	 * @return the created state.
	 */
	public static MaterialListPriceCached create(final ComponentCommon master,final MaterialList materials,final int overallPrice){
		return new MaterialListPriceCached(master,materials,overallPrice);
	}
	
	/**
	 * Constructor of MaterialListPriceCached.
	 * @param master is the ComponentCommon of this state.
	 * @param materials is the cached MaterialList.
	 * @param overallPrice is the cached overall price of the master.
	 */
	private MaterialListPriceCached(final ComponentCommon master,final MaterialList materials,final int overallPrice) {
		super(master, materials);
		this.overallPrice = overallPrice;
	}

	@Override
	public MaterialList getMaterialList() {
		return this.getMaterials();
	}
	
	@Override
	public int getOverallPrice() {
		return overallPrice;
	}

	@Override
	protected void handlePriceChangedEvent(final PriceChangedEvent priceChangedEvent) {
		this.getMaster().setState(MaterialListCached.create(this.getMaster(), this.getMaterials()));
	}

	@Override
	protected void handleStructureChangedEvent(
			final StructureChangedEvent structureChangedEvent) {
		this.getMaster().setState(NotCached.create(this.getMaster()));
	}

	@Override
	public String toString(){
		return PartsListConstants.materialListPriceCached;
	}
}